package com.thinkit.bigdata.web.service.impl.config;

import com.thinkit.bigdata.core.feature.orm.mybatis.Page;
import com.thinkit.bigdata.web.coremet.SystemStatic;
import com.thinkit.bigdata.web.dao.config.SysStatusAttMapper;
import com.thinkit.bigdata.web.model.config.SysStatusAtt;
import com.thinkit.bigdata.web.model.config.SysStatusAttExample;
import com.thinkit.bigdata.web.service.config.StatusAttService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * Created by lihongli on 2018/8/31
 */
@Service
public class StatusAttServiceImpl implements StatusAttService {

    @Resource
    private SysStatusAttMapper mapper;

    @Override
    public List<SysStatusAtt> selectByExample(SysStatusAttExample example) {
        return mapper.selectByExample(example);
    }

    @Override
    public List<SysStatusAtt> selectByExample(Page<SysStatusAtt> page, SysStatusAttExample example) {
        return mapper.selectByExample(page, example);
    }

    @Override
    public Integer countByExample(SysStatusAttExample example) {
        return mapper.countByExample(example);
    }

    @Override
    public Integer insert(SysStatusAtt record) {
        return mapper.insert(record);
    }

    @Override
    public SysStatusAtt statusAttGetByPK(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public Integer update(SysStatusAtt record) {
        if ("audio_onhook".equals(record.getType())) {
            SysStatusAttExample exampleHook = new SysStatusAttExample();
            exampleHook.createCriteria().andTypeEqualTo("audio_onhook");
            List<SysStatusAtt> onHookList = mapper.selectByExample(exampleHook);
            SystemStatic.ONHOOK_MAP.clear();
            for (SysStatusAtt onHook : onHookList) {
                SystemStatic.ONHOOK_MAP.put(onHook.getValue(), onHook.getName());
            }
        }
        if ("audio_satisfaction".equals(record.getType())) {
            SysStatusAttExample exampleSatisfaction = new SysStatusAttExample();
            exampleSatisfaction.createCriteria().andTypeEqualTo("audio_satisfaction");
            List<SysStatusAtt> satisfactionList = mapper.selectByExample(exampleSatisfaction);
            for (SysStatusAtt satisfaction : satisfactionList) {
                SystemStatic.SATISFACTION_MAP.clear();
                SystemStatic.SATISFACTION_MAP.put(satisfaction.getValue(), satisfaction.getName());
            }
        }
        if ("audio_customer_level".equals(record.getType())) {
            SysStatusAttExample exampleCustomerlevel = new SysStatusAttExample();
            exampleCustomerlevel.createCriteria().andTypeEqualTo("audio_customer_level");
            List<SysStatusAtt> customerLevelList = mapper.selectByExample(exampleCustomerlevel);
            for (SysStatusAtt customerLevel : customerLevelList) {
                SystemStatic.CUSTOMERLEVEL_MAP.clear();
                SystemStatic.CUSTOMERLEVEL_MAP.put(customerLevel.getValue(), customerLevel.getName());
            }
        }

        return mapper.updateByPrimaryKey(record);
    }

    @Override
    public Integer delete(Long id) {
        return mapper.deleteByPrimaryKey(id);
    }
}
